/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.hibernate;

import java.util.Locale;
import java.util.regex.Pattern;

import org.hibernate.boot.model.naming.EntityNaming;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
import org.hibernate.boot.model.source.spi.AttributePath;

public class RrxImplicitNamingStrategy extends ImplicitNamingStrategyJpaCompliantImpl {

  private static final long serialVersionUID = -3526713298000048462L;
  
  public Pattern pattern = Pattern.compile("([a-z])([A-Z])");

  protected String transformAttributePath(AttributePath attributePath) {
    String property = attributePath.getProperty();
    String replacement = "$1_$2";
    return pattern.matcher(property).replaceAll(replacement).toLowerCase(Locale.getDefault());
  }

  protected String transformEntityName(EntityNaming entityNaming) {
    String name = super.transformEntityName(entityNaming);
    String replacement = "$1_$2";
    return pattern.matcher(name).replaceAll(replacement).toLowerCase(Locale.getDefault());
  }
}
